package demo2;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-09-02
 * Time: 17:41
 */
public class Test01 {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        //for循环
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();
        //for-each循环
        for(Integer integer : arrayList) {
            System.out.print(integer + " ");
        }
        System.out.println();
        //迭代器
        Iterator<Integer> it = arrayList.iterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
    }
    public static void main1(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0);

        ArrayList<Integer> arrayList1 = new ArrayList<>(10);
        arrayList1.add(1);
        arrayList1.add(2);
        System.out.println(arrayList1);

        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList1);
        arrayList2.add(3);
        System.out.println(arrayList2);



    }
}
